package com.mroapp.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.mroapp.R;
import com.mroapp.base.BaseActivity;

/**
 * Created by apple on 16/7/12.
 */
public class APP {
    public static Runnable tip;
    private static Toast toast;


    /** 打印异常信息 */
    public static void exception(String tag, Exception e) {
        BaseActivity.Log_error(tag + " Exception：");
        e.printStackTrace();
    }
    public static void Tip(final String msg){
        tip=new Runnable() {
            @Override
            public void run() {

            }
        };
    }

    /**
     * 展示提示信息
     */
    public static void tip(Context context, String msg) {
        tip(context, msg, 0);
    }

    /**
     * 展示提示信息
     *
     * @param time
     *            = 0 代表短时间
     */
    public static void tip(Context context, String msg, int time) {
        TextView message;
        if (toast == null) {
            View view = LayoutInflater.from(context).inflate(R.layout.mytoast, null);
            message = (TextView) view.findViewById(R.id.toast_tip);
            message.setText(msg);
            toast = new Toast(context);
            if (0 == time) {
                toast.setDuration(Toast.LENGTH_SHORT);
            } else {
                toast.setDuration(Toast.LENGTH_LONG);
            }
            toast.setView(view);
        } else {
            View layout = toast.getView();
            message = (TextView) layout.findViewById(R.id.toast_tip);
            message.setText(msg);
        }
        // 距离顶部100dp
        // toast.setGravity(Gravity.CENTER, 0, -(Sys.getScreenHeight(context) /
        // 2 - Sys.Dp2Px(context, 100)));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 取消提示信息
     */
    public void dismissTip() {
        if (toast != null) {
            toast.cancel();
        }
    }



}
